<?php
namespace Admin\Controller;
use Think\Controller;
class IndexController extends Controller 
{
  	public function index()
		{

			login('您好，请先登录');										//登录记录表		
			$sql=M('t_login_record')->find();			//登录用户的信息

			//得到  当前数据库时间戳大于当前时间戳的数据
			$this->assign('User_Profile',$User_Profile);									//传递数组
			$this->assign('sql',$sql);
			$this->display();
		}
		/* 游戏用户信息 */
	public function grabble()
	{
		 login('您好，请先登录');
		$t_users= M('','t_users','DB_CONFIG1'); 
		$map['account']=array('like','WX%');
		//玩家总数
		$count      = $t_users->where($map)->count();
		$Page       = new \Org\Bjy\Page($count,15);
		$show       = $Page->show();
		
		$a = $Page->firstRow;
		$b = $Page->listRows;
		$result = M('','','DB_CONFIG1')->query("SELECT * FROM t_users LEFT JOIN (SELECT userid as id,MAX(login_time) FROM t_login_log group by id) AS tb1 ON t_users.userid = tb1.id WHERE t_users.account LIKE 'wx%' ORDER BY t_users.userid DESC limit $a, $b");
		//dump($result);die;
		if(IS_GET)
		{
			$userid=$_GET['userid'];
			$name=$_GET['name'];
			$accounts=$_SESSION['accounts'];
			if($_GET['userid']!="" || $_GET['name']!="")
			{   
				$w['userid']=array('like','%'.$_GET['userid'].'%');												//把数据写到空数组去  
			    $w['name']=array('like','%'.$_GET['name'].'%');
			    $count      = $t_users->where($map)->where($w)->count();
				//dump($count);die; 		
				$Page       = new \Org\Bjy\Page($count,15);
				$show       = $Page->show();
				$a = $Page->firstRow;
		        $b = $Page->listRows;

				$result=M('','','DB_CONFIG1')->query("SELECT * FROM t_users LEFT JOIN (SELECT userid as id,MAX(login_time) FROM t_login_log GROUP BY id) as tb1 ON t_users.userid=tb1.id WHERE t_users.account LIKE 'wx%' and t_users.userid like '%".$userid."%' AND t_users.name like '%".$name."%' order by t_users.userid asc limit $a, $b" );
				if($result)
				{
					$state=0;
					M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,state)values('$accounts','查询游戏用户信息','$state')");
				}else
				{
					$state=1;
					M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,state)values('$accounts','查询游戏用户信息','$state')");
				}
			}	
			if($_GET['sdate']!="" || $_GET['edate']!="")
			{
				$sdate=$_GET['sdate'];
				$edate=$_GET['edate'];
				//dump($edate);die;
				$arr['create_time']=array('between',array($sdate,$edate));
			    $count      = $t_users->where($map)->where($arr)->count();
				$Page       = new \Org\Bjy\Page($count,15);
				$show       = $Page->show();
				$a = $Page->firstRow;
		        $b = $Page->listRows;

				$result=	M('','','DB_CONFIG1')->query("SELECT t_users.*,tb1.Mt FROM t_users LEFT JOIN (SELECT userid,MAX(login_time) AS Mt FROM t_login_log GROUP BY userid) AS tb1 ON t_users.userid=tb1.userid WHERE t_users.account LIKE 'wx%' AND t_users.create_time  BETWEEN '".$sdate."' AND '".$edate."' limit $a, $b"); 
				if($result)
				{
					$state=0;
					$accounts=$_SESSION['accounts'];
					M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,state)values('$accounts','查询游戏用户信息','$state')");
				}else
				{
					$state=1;
					$accounts=$_SESSION['accounts'];
					M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,state)values('$accounts','查询游戏用户信息','$state')");
				}
			}
		}
		
		


		$this->assign('page',$show);
		$this->assign('result',$result);
		$this->assign('count',$count);
		$this->display();
	}

		 /* 在线用户页面  */ 
	public function sinfo()
	{ 
	login('您好，请先登录');
		 $t_users= M('','t_users','DB_CONFIG1'); 
		$map['account']=array('like','WX%');
		$count      = $t_users->where('online=1')->where($map)->count();
		$Page       = new \Org\Bjy\Page($count,15);
		$show       = $Page->show();
		$result = $t_users->where('online=1')->where($map)->order('userid desc')->limit($Page->firstRow.','.$Page->listRows)->select();		
		foreach($map as $key=>$val) { 
		$Page->parameter   .=   "$key=".urlencode($val).'&';
		}
		
		if(IS_GET)
		{
			$userid=$_GET['userid'];
			$name=$_GET['name'];
			$accounts=$_SESSION['accounts'];
			if($_GET['userid']!="" || $_GET['name']!="" AND $_GET['sdate']=="" AND $_GET['edate']=="" )
			{
				$w['name']=array('like','%'.$name.'%');											//把数据写到空数组去
				$w['userid']=array('like','%'.$userid.'%');										//把数据写到空数组
				$count      = $t_users->where('online=1')->where($map)->where($w)->count();
				$Page       = new \Org\Bjy\Page($count,15);
				$show       = $Page->show();
				$result=$t_users->where('online=1')->where($w)->where($map)->limit($Page->firstRow.','.$Page->listRows)->select();//echo $t_users->_sql();die;
				if($result)
				{
					$state=0;
					$accounts=$_SESSION['accounts'];
					M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,state)values('$accounts','查询游戏用户信息','$state')");
				}else
				{
					$state=1;
					$accounts=$_SESSION['accounts'];
					M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,state)values('$accounts','查询游戏用户信息','$state')");
				}
			}
			if($_GET['userid']=="" AND $_GET['name']=="" AND $_GET['sdate']!="" || $_GET['edate']!="")
			{
				$arr['create_time']=array('between',array($_GET['sdate'],$_GET['edate']));
				$count      = $t_users->where('online=1')->where($map)->where($arr)->count();
				$Page       = new \Org\Bjy\Page($count,15);
				$show       = $Page->show();
				$result=$t_users->where('online=1')->where($map)->where($arr)->limit($Page->firstRow.','.$Page->listRows)->select();//echo $t_users->_sql();die;
				if($result)
				{
					$state=0;
					$accounts=$_SESSION['accounts'];
					M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,state)values('$accounts','查询游戏用户信息','$state')");
				}else
				{
					$state=1;
					$accounts=$_SESSION['accounts'];
					M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,state)values('$accounts','查询游戏用户信息','$state')");
				}
			}
		}	
		$this->assign('page',$show);
		$this->assign('result',$result);
		$this->display();
	}
	/*      修改密码           */
	public function modipass()
	{
				login('您好，请先登录');

			$t_agent= M('','t_agent','DB_CONFIG0'); 
			if(IS_POST)
			{
				if($_POST['password']=="" || $_POST['passwordd']=="")
				{
					error('密码不能为空');
				}
				if($_POST['password']!=$_POST['passwordd'])
				{
					error('您输入的新密码和确认密码不一致，请重新输入');
				}
				if(strlen($_POST['password'])<6)
				{
					error('请按照规范更改密码');
				}
				if(MD5($_POST['password'])==MD5($_POST['passwordd']))
				{
					$t_agent->password=MD5($_POST['password']);
					$new_password=$t_agent->where('userid='.$_SESSION['userid'])->save();
					if($new_password)
					{
						$state=0;
						$accounts=$_SESSION['accounts'];
						M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,state)values('$accounts','更改用户密码','$state')");
					}else
					{
						$state=1;
						$accounts=$_SESSION['accounts'];
						M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,state)values('$accounts','更改用户密码','$state')");
					}
					if($new_password)
					{
						login_error('密码重置成功，请保管好您的密码。');
					}
					else
					{
						error('系统繁忙，请您重再次输入');
					}
				}
			}
		$this->display();
	}
	/*   游戏历史记录  */
	public function loadgame()
	{
			login('您好，请先登录');
		$t_rooms= M('','t_each_round_history','DB_CONFIG1');
		//分页查询
		$sear['']=array();
		$count      = $t_rooms->where($w)->count();
		$Page       = new \Org\Bjy\Page($count,25);
		$show       = $Page->show();
		$loadgame = $t_rooms->limit($Page->firstRow.','.$Page->listRows)->select();
		$this->assign('page',$show);	
		//传递数组   解析  json
		$list=$t_rooms->where('room_id='.I('get.room_id'))->select();
		$count = 0;
		$seats_setting=array();
		//$aa=array(banker_index=>$list)
		foreach ($list as $k=>$v)
		{
			$json=$v['history'];
			$obj=json_decode($json,true);
			$seats=$obj['seats'];
			$seats_setting[$count] = $seats;
			$count = $count +1;
		}
		//dump($seats_setting);die;
		$banker_index = array();
		for($i=0;$i<=$k;$i++){
			$banker_index[$i]=$list[$i]['banker_index'];
		}
		for($a=0;$a<count($seats_setting); $a++) {
			for($b=0;$b<count($seats_setting[$a]); $b++) {
				$seats_setting[$a][$b]["banker_index"]=$banker_index[$a];
			}
		}
			//dump($seats_setting[$a][$b]);die;
		$this->assign('seats_setting',$seats_setting);
		$this->assign('list',$list);
		$this->display();
	}
	//游戏记录
	public function history()
	{
		//分页
		$t_rooms= M('','t_each_round_history','DB_CONFIG1');	
		$w=array();
		$count      = $t_rooms->where($w)->count();
		$Page       = new \Org\Bjy\Page($count,25);
		$show       = $Page->show();
		$list = $t_rooms->field('*,room_id,max(round_no)')->group('room_id')->where($w)->limit($Page->firstRow.','.$Page->listRows)->order('begin_time desc')->select();
		//dump($list);die;
		
		//接收数据  查询
		if(IS_GET)
		{
			
			if($_GET['userid']!="" || $_GET['name']!="")
			{
				$w['room_uuid']=array('like','%'.$_GET['userid'].'%');//把数据写到空数组去  
				$w['room_id']=array('like','%'.$_GET['name'].'%');//把数据写到空数组	
				$count      = $t_rooms->field('*,room_id,max(round_no)')->where($w)->count('round_no');
				$Page       = new \Org\Bjy\Page($count,15);
				$show       = $Page->show();			
				$list=$t_rooms->field('*,room_id,max(round_no)')->group('room_id')->where($w)->limit($Page->firstRow.','.$Page->listRows)->select();
				//dump($count);die;
				if($list)
				{
					$state=0;
					$accounts=$_SESSION['accounts'];
					M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,state)values('$accounts','给玩家冲钻信息查询','$state')");
				}else
				{
					$state=1;
					$accounts=$_SESSION['accounts'];
					M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,state)values('$accounts','给玩家冲钻信息查询','$state')");
				}
			}	
			if($_GET['sdate']!="" || $_GET['edate']!="")
			{
				$sdate=$_GET['sdate']; //get来的时间转为时间戳
				$edate=$_GET['edate'];	//get来的时间转为时间戳
				$arr['begin_time']=array('between',array($sdate,$edate));
				$count      = $t_rooms->where($arr)->count();
				$Page       = new \Org\Bjy\Page($count,15);
				$show       = $Page->show();
				$list=$t_rooms->field('*,room_id,max(round_no)')->group('room_id')->where($arr)->limit($Page->firstRow.','.$Page->listRows)->select();//时间不符合    需要修正！！！！
				if($list)
				{
					$state=0;
					$accounts=$_SESSION['accounts'];
					M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,state)values('$accounts','给玩家冲钻信息查询','$state')");
				}else
				{
					$state=1;
					$accounts=$_SESSION['accounts'];
					M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,state)values('$accounts','给玩家冲钻信息查询','$state')");
				}
			}
		}
		$this->assign('page',$show);
		$this->assign('list',$list);
		$this->display();
	}
			/* 转账给游戏玩家记录 */
	public function playercharge()
	{
				login('您好，请先登录');
		$t_agent_add_cards_to_user= M('','t_agent_add_cards_to_user','DB_CONFIG0');
		//$t_users= M('','t_users','DB_CONFIG1');
		 
		$w=array();
		$count      = $t_agent_add_cards_to_user->where($w)->count();
		//dump($count);die;
		$Page       = new \Org\Bjy\Page($count,20);
		$show       = $Page->show();
		$loadgame = $t_agent_add_cards_to_user->where($w)->order('regtime desc')->limit($Page->firstRow.','.$Page->listRows)->select();
			
		
		//$userid=$_GET['userid'];
		if(IS_GET)
		{
			
			if($_GET['userid']!="" || $_GET['name']!="")
			{   
				$userid=$_GET['userid'];
			    $name=$_GET['name'];
				$w['recipient']=array('like','%'.$userid.'%');//把数据写到空数组去  
				$w['name']=array('like','%'.$name.'%');//把数据写到空数组
				$count      = $t_agent_add_cards_to_user->where($w)->count();
				$Page       = new \Org\Bjy\Page($count,20);
				$show       = $Page->show();				
				$loadgame=$t_agent_add_cards_to_user->where($w)->limit($Page->firstRow.','.$Page->listRows)->select();

				if($loadgame)
				{
					$state=0;
					$accounts=$_SESSION['accounts'];
					M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,state)values('$accounts','给玩家冲钻信息查询','$state')");
				}else
				{
					$state=1;
					$accounts=$_SESSION['accounts'];
					M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,state)values('$accounts','给玩家冲钻信息查询','$state')");
				}
			}	
			if($_GET['sdate']!="" || $_GET['edate']!="")
			{
				$sdate=$_GET['sdate']; //get来的时间转为时间戳
				$edate=$_GET['edate'];	//get来的时间转为时间戳
				$arr['regtime']=array('between',array($sdate,$edate));
				$count      = $t_agent_add_cards_to_user->where($arr)->count();
				$Page       = new \Org\Bjy\Page($count,20);
				$show       = $Page->show();
				$loadgame=$t_agent_add_cards_to_user->where($arr)->limit($Page->firstRow.','.$Page->listRows)->select();//时间不符合    需要修正！！！！
				if($loadgame)
				{
					$state=0;
					$accounts=$_SESSION['accounts'];
					M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,state)values('$accounts','给玩家冲钻信息查询','$state')");
				}else
				{
					$state=1;
					$accounts=$_SESSION['accounts'];
					M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,state)values('$accounts','给玩家冲钻信息查询','$state')");
				}
			}
		}
		$this->assign('page',$show);
		$this->assign('loadgame',$loadgame);
		$this->display();
	}
				/* 充值信息记录 订单成功*/
	public function recharge()
	{
		login('您好，请先登录');
		$yp_apply_order= M('','yp_apply_order','DB_CONFIG0');
		
		$count      = $yp_apply_order->where('order_status=1')->count();
		$Page       = new \Org\Bjy\Page($count,20);
		$show       = $Page->show();
		$loadgame = $yp_apply_order->order('times desc')->where('order_status=1')->limit($Page->firstRow.','.$Page->listRows)->select();
		//dump($loadgame);die;
		
				
		if(IS_GET)
		{
			if($_GET['userid']!="" || $_GET['order_no']!="")
			{
				$w['oper_account']=array('like','%'.$_GET['userid'].'%');//id 查询
				$w['order_no']=array('like','%'.$_GET['order_no'].'%');//订单号查询
				$count  = $yp_apply_order->where($w)->where('order_status=1')->count();
				//dump($count);die;
				$Page     = new \Org\Bjy\Page($count,1000);
		        $show     = $Page->show();
				$loadgame=$yp_apply_order->where($w)->where('order_status=1')->order('times desc')->limit($Page->firstRow.','.$Page->listRows)->select();
				if($loadgame)
				{
					$state=0;
					$accounts=$_SESSION['accounts'];
					M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,state)values('$accounts','查询官方给玩家冲钻记录','$state')");
				}else
				{
					$state=1;
					$accounts=$_SESSION['accounts'];
					M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,state)values('$accounts','查询官方给玩家冲钻记录','$state')");
				}
			}
							
			if($_GET['sdate']!="" || $_GET['edate']!="")
			{
				$arr['times']=array('between',array($_GET['sdate'],$_GET['edate']));
				$count  = $yp_apply_order->where($arr)->where('order_status=1')->count();
				//dump($count);die;
				$Page     = new \Org\Bjy\Page($count,1000);
		        $show     = $Page->show(); 
				$loadgame=M('yp_apply_order')->where($arr)->where('order_status=1')->order('times desc')->limit($Page->firstRow.','.$Page->listRows)->select();	
				if($loadgame)
				{
					$state=0;
					$accounts=$_SESSION['accounts'];
					M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,state)values('$accounts','查询官方给玩家冲钻记录','$state')");
				}else
				{
					$state=1;
					$accounts=$_SESSION['accounts'];
					M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,state)values('$accounts','查询官方给玩家冲钻记录','$state')");
				}
			}
			
			if($_GET['rmb']!="")
			{
				if($_GET['rmb']==1)
				{   
					$get_select = "40元";
					$count  = $yp_apply_order->where($arr)->where('order_gems=100 and order_status=1')->count();
					//dump($count);die;
					$Page     = new \Org\Bjy\Page($count,1000);
			        $show     = $Page->show(); 
					$loadgame=M('yp_apply_order')->where('order_gems=100 and order_status=1')->order('times desc')->limit($Page->firstRow.','.$Page->listRows)->select();

				}
				if($_GET['rmb']==2)
				{   
					$post_select = "110元";
					$count  = $yp_apply_order->where($arr)->where('order_gems=300 and order_status=1')->count();
					//dump($count);die;
					$Page     = new \Org\Bjy\Page($count,1000);
			        $show     = $Page->show(); 
					$loadgame=M('yp_apply_order')->where('order_gems=300 and order_status=1')->order('times desc')->
					          limit($Page->firstRow.','.$Page->listRows)->select();	
				}
				if($_GET['rmb']==3)
				{   
					$post_select = "350元";
					$count  = $yp_apply_order->where($arr)->where('order_gems=1000 and order_status=1')->count();
					//dump($count);die;
					$Page     = new \Org\Bjy\Page($count,1000);
			        $show     = $Page->show(); 
					$loadgame=M('yp_apply_order')->where('order_gems=1000 and order_status=1')->order('times desc')->
					          limit($Page->firstRow.','.$Page->listRows)->select();
				}				
				if($_GET['rmb']==4)
				{   
					$post_select = "1000元";
					$count  = $yp_apply_order->where($arr)->where('order_gems=3000 and order_status=1')->count();
					//dump($count);die;
					$Page     = new \Org\Bjy\Page($count,1000);
			        $show     = $Page->show(); 
					$loadgame=M('yp_apply_order')->where('order_gems=3000 and order_status=1')->order('times desc')->limit($Page->firstRow.','.$Page->listRows)->select();
				}				
				if($_GET['rmb']==5)
				{   
					$post_select = "3000元";
					$count  = $yp_apply_order->where($arr)->where('order_gems=10000 and order_status=1')->count();
					//dump($count);die;
					$Page     = new \Org\Bjy\Page($count,1000);
			        $show     = $Page->show(); 
					$loadgame=M('yp_apply_order')->where('order_gems=10000 and order_status=1')->order('times desc')->limit($Page->firstRow.','.$Page->listRows)->select();
				}				
			}
		}
		//dump($post_select);die;
		$this->assign('page',$show);
		$this->assign('post_select',$post_select);
		$this->assign('loadgame',$loadgame);
		$this->display();
	}
				/* 充值信息记录 所有订单*/
	public function recharge00()
	{
		login('您好，请先登录');
		$yp_apply_order= M('','yp_apply_order','DB_CONFIG0');
		
		$count      = $yp_apply_order->count();
		$Page       = new \Org\Bjy\Page($count,15);
		$show       = $Page->show();
		$loadgame = $yp_apply_order->order('times desc')->limit($Page->firstRow.','.$Page->listRows)->select();
		//dump($loadgame);die;
		
				
		if(IS_GET)
		{//id 查询
			if($_GET['userid']!="")
			{
				$w['oper_account']=array('like','%'.I('get.userid').'%');//把数据写到空数组去  
				$count      = $yp_apply_order->where($w)->count();
				$Page       = new \Org\Bjy\Page($count,1000);
				$show       = $Page->show();
				$loadgame=$yp_apply_order->where($w)->order('times desc')->limit($Page->firstRow.','.$Page->listRows)->select();
				if($loadgame)
				{
					$state=0;
					$accounts=$_SESSION['accounts'];
					M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,state)values('$accounts','查询官方给玩家冲钻记录','$state')");
				}else
				{
					$state=1;
					$accounts=$_SESSION['accounts'];
					M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,state)values('$accounts','查询官方给玩家冲钻记录','$state')");
				}
			}
			
			//订单号查询
			if($_GET['order_no']!="")
			{
				$w['order_no']=array('like','%'.I('get.order_no').'%');//把数据写到空数组去
				$count      = $yp_apply_order->where($w)->count();
				$Page       = new \Org\Bjy\Page($count,1000);
				$show       = $Page->show();  
				$loadgame=$yp_apply_order->where($w)->order('times desc')->limit($Page->firstRow.','.$Page->listRows)->select();
				if($loadgame)
				{
					$state=0;
					$accounts=$_SESSION['accounts'];
					M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,state)values('$accounts','查询官方给玩家冲钻记录','$state')");
				}else
				{
					$state=1;
					$accounts=$_SESSION['accounts'];
					M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,state)values('$accounts','查询官方给玩家冲钻记录','$state')");
				}
			}				
			if($_GET['sdate']!="" || $_GET['edate']!="")
			{
				$arr['times']=array('between',array($_GET['sdate'],$_GET['edate']));
				$count      = $yp_apply_order->where($arr)->count();
				$Page       = new \Org\Bjy\Page($count,1000);
				$show       = $Page->show(); 
				$loadgame=M('yp_apply_order')->where($arr)->order('times desc')->limit($Page->firstRow.','.$Page->listRows)->select();	
				if($loadgame)
				{
					$state=0;
					$accounts=$_SESSION['accounts'];
					M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,state)values('$accounts','查询官方给玩家冲钻记录','$state')");
				}else
				{
					$state=1;
					$accounts=$_SESSION['accounts'];
					M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,state)values('$accounts','查询官方给玩家冲钻记录','$state')");
				}
			}
			
			if($_GET['rmb']!="")
			{
				if($_GET['rmb']==1)
				{   
					$post_select = "40元";
					$count  = $yp_apply_order->where('order_gems=100')->count();
					//dump($count);die;
					$Page     = new \Org\Bjy\Page($count,1000);
			        $show     = $Page->show(); 
					$loadgame=M('yp_apply_order')->where('order_gems=100')->order('times desc')->
					          limit($Page->firstRow.','.$Page->listRows)->select();

				}
				if($_GET['rmb']==2)
				{   
					$post_select = "110元";
					$count  = $yp_apply_order->where('order_gems=300')->count();
					//dump($count);die;
					$Page     = new \Org\Bjy\Page($count,1000);
			        $show     = $Page->show(); 
					$loadgame=M('yp_apply_order')->where('order_gems=300')->order('times desc')->
					          limit($Page->firstRow.','.$Page->listRows)->select();	
				}
				if($_GET['rmb']==3)
				{   
					$post_select = "350元";
					$count  = $yp_apply_order->where('order_gems=1000')->count();
					//dump($count);die;
					$Page     = new \Org\Bjy\Page($count,1000);
			        $show     = $Page->show(); 
					$loadgame=M('yp_apply_order')->where('order_gems=1000')->order('times desc')->
					          limit($Page->firstRow.','.$Page->listRows)->select();
				}				
				if($_GET['rmb']==4)
				{   
					$post_select = "1000元";
					$count  = $yp_apply_order->where('order_gems=3000')->count();
					//dump($count);die;
					$Page     = new \Org\Bjy\Page($count,1000);
			        $show     = $Page->show(); 
					$loadgame=M('yp_apply_order')->where('order_gems=3000')->order('times desc')->
					          limit($Page->firstRow.','.$Page->listRows)->select();
				}				
				if($_GET['rmb']==5)
				{   
					$post_select = "3000元";
					$count  = $yp_apply_order->where('order_gems=10000')->count();
					//dump($count);die;
					$Page     = new \Org\Bjy\Page($count,1000);
			        $show     = $Page->show(); 
					$loadgame=M('yp_apply_order')->where('order_gems=10000')->order('times desc')->
					          limit($Page->firstRow.','.$Page->listRows)->select();
				}				
			}
		}
		//dump($post_select);die;
		$this->assign('page',$show);
		$this->assign('post_select',$post_select);
		$this->assign('loadgame',$loadgame);
		$this->display();
	}
             /* 充值信息记录 订单异常*/
	public function recharge02()
	{
		login('您好，请先登录');
		$yp_apply_order= M('','yp_apply_order','DB_CONFIG0');
		
		$count      = $yp_apply_order->where('order_status=0')->count();
		$Page       = new \Org\Bjy\Page($count,20);
		$show       = $Page->show();
		$loadgame = $yp_apply_order->order('times desc')->where('order_status=0')->limit($Page->firstRow.','.$Page->listRows)->select();
		//dump($loadgame);die;
		
				
		if(IS_GET)
		{//id 查询
			if($_GET['userid']!="")
			{
				$w['oper_account']=array('like','%'.I('get.userid').'%');//把数据写到空数组去 
				$count      = $yp_apply_order->where($w)->where('order_status=0')->count();
				$Page       = new \Org\Bjy\Page($count,1000);
				$show       = $Page->show(); 
				$loadgame=$yp_apply_order->where($w)->where('order_status=0')->order('times desc')->limit($Page->firstRow.','.$Page->listRows)->select();
				if($loadgame)
				{
					$state=0;
					$accounts=$_SESSION['accounts'];
					M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,state)values('$accounts','查询官方给玩家冲钻记录','$state')");
				}else
				{
					$state=1;
					$accounts=$_SESSION['accounts'];
					M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,state)values('$accounts','查询官方给玩家冲钻记录','$state')");
				}
			}
			//订单号查询
			if($_GET['order_no']!="")
			{
				$w['order_no']=array('like','%'.I('get.order_no').'%');//把数据写到空数组去 
				$count      = $yp_apply_order->where($w)->where('order_status=0')->count();
				$Page       = new \Org\Bjy\Page($count,1000);
				$show       = $Page->show();  
				$loadgame=$yp_apply_order->where($w)->where('order_status=0')->order('times desc')->limit($Page->firstRow.','.$Page->listRows)->select();
				if($loadgame)
				{
					$state=0;
					$accounts=$_SESSION['accounts'];
					M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,state)values('$accounts','查询官方给玩家冲钻记录','$state')");
				}else
				{
					$state=1;
					$accounts=$_SESSION['accounts'];
					M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,state)values('$accounts','查询官方给玩家冲钻记录','$state')");
				}
			}				
			if($_GET['sdate']!="" || $_GET['edate']!="")
			{
				$arr['times']=array('between',array($_GET['sdate'],$_GET['edate']));
				$count      = $yp_apply_order->where($arr)->where('order_status=0')->count();
				$Page       = new \Org\Bjy\Page($count,1000);
				$show       = $Page->show();
				$loadgame=M('yp_apply_order')->where($arr)->where('order_status=0')->order('times desc')->limit($Page->firstRow.','.$Page->listRows)->select();	
				if($loadgame)
				{
					$state=0;
					$accounts=$_SESSION['accounts'];
					M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,state)values('$accounts','查询官方给玩家冲钻记录','$state')");
				}else
				{
					$state=1;
					$accounts=$_SESSION['accounts'];
					M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,state)values('$accounts','查询官方给玩家冲钻记录','$state')");
				}
			}
			
			if($_GET['rmb']!="")
			{
				if($_GET['rmb']==1)
				{   
					$post_select = "40元";
					$count  = $yp_apply_order->where('order_gems=100 and order_status=0')->count();
					//dump($count);die;
					$Page     = new \Org\Bjy\Page($count,1000);
			        $show     = $Page->show(); 
					$loadgame=M('yp_apply_order')->where('order_gems=100 and order_status=0')->order('times desc')->limit($Page->firstRow.','.$Page->listRows)->select();

				}
				if($_GET['rmb']==2)
				{   
					$post_select = "110元";
					$count  = $yp_apply_order->where('order_gems=300 and order_status=0')->count();
					//dump($count);die;
					$Page     = new \Org\Bjy\Page($count,1000);
			        $show     = $Page->show(); 
					$loadgame=M('yp_apply_order')->where('order_gems=300 and order_status=0')->order('times desc')->limit($Page->firstRow.','.$Page->listRows)->select();	
				}
				if($_GET['rmb']==3)
				{   
					$post_select = "350元";
					$count  = $yp_apply_order->where('order_gems=1000 and order_status=0')->count();
					//dump($count);die;
					$Page     = new \Org\Bjy\Page($count,1000);
			        $show     = $Page->show(); 
					$loadgame=M('yp_apply_order')->where('order_gems=1000 and order_status=0')->order('times desc')->limit($Page->firstRow.','.$Page->listRows)->select();
				}				
				if($_GET['rmb']==4)
				{   
					$post_select = "1000元";
					$count  = $yp_apply_order->where('order_gems=3000 and order_status=0')->count();
					//dump($count);die;
					$Page     = new \Org\Bjy\Page($count,1000);
			        $show     = $Page->show(); 
					$loadgame=M('yp_apply_order')->where('order_gems=3000 and order_status=0')->order('times desc')->limit($Page->firstRow.','.$Page->listRows)->select();
				}				
				if($_GET['rmb']==5)
				{   
					$post_select = "3000元";
					$count  = $yp_apply_order->where('order_gems=10000 and order_status=0')->count();
					//dump($count);die;
					$Page     = new \Org\Bjy\Page($count,1000);
			        $show     = $Page->show(); 
					$loadgame=M('yp_apply_order')->where('order_gems=10000 and order_status=0')->order('times desc')->limit($Page->firstRow.','.$Page->listRows)->select();
				}				
			}
		}
		//dump($post_select);die;
		$this->assign('page',$show);
		$this->assign('post_select',$post_select);
		$this->assign('loadgame',$loadgame);
		$this->display();
	}
              /* 充值信息记录 订单处理中*/
	// public function recharge03()
	// {
	// 	login('您好，请先登录');
	// 	$yp_apply_order= M('','yp_apply_order','DB_CONFIG0');
		
	// 	$count      = $yp_apply_order->where('order_status=2')->count();
	// 	$Page       = new \Org\Bjy\Page($count,15);
	// 	$show       = $Page->show();
	// 	$loadgame = $yp_apply_order->order('times desc')->where('order_status=2')->limit($Page->firstRow.','.$Page->listRows)->select();
	// 	//dump($loadgame);die;
		
				
	// 	if(IS_GET)
	// 	{//id 查询
	// 		if($_GET['userid']!="")
	// 		{
	// 			$w['oper_account']=array('like','%'.I('get.userid').'%');//把数据写到空数组去  
	// 			$loadgame=$yp_apply_order->where($w)->where('order_status=2')->select();
	// 			if($loadgame)
	// 			{
	// 				$state=0;
	// 				$accounts=$_SESSION['accounts'];
	// 				M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,state)values('$accounts','查询官方给玩家冲钻记录','$state')");
	// 			}else
	// 			{
	// 				$state=1;
	// 				$accounts=$_SESSION['accounts'];
	// 				M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,state)values('$accounts','查询官方给玩家冲钻记录','$state')");
	// 			}
	// 		}
	// 		//订单号查询
	// 		if($_GET['order_no']!="")
	// 		{
	// 			$w['order_no']=array('like','%'.I('get.order_no').'%');//把数据写到空数组去  
	// 			$loadgame=$yp_apply_order->where($w)->where('order_status=2')->select();
	// 			if($loadgame)
	// 			{
	// 				$state=0;
	// 				$accounts=$_SESSION['accounts'];
	// 				M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,state)values('$accounts','查询官方给玩家冲钻记录','$state')");
	// 			}else
	// 			{
	// 				$state=1;
	// 				$accounts=$_SESSION['accounts'];
	// 				M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,state)values('$accounts','查询官方给玩家冲钻记录','$state')");
	// 			}
	// 		}				
	// 		if($_GET['sdate']!="" || $_GET['edate']!="")
	// 		{
	// 			$arr['times']=array('between',array($_GET['sdate'],$_GET['edate']));
	// 			$loadgame=M('yp_apply_order')->where($arr)->where('order_status=2')->select();	
	// 			if($loadgame)
	// 			{
	// 				$state=0;
	// 				$accounts=$_SESSION['accounts'];
	// 				M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,state)values('$accounts','查询官方给玩家冲钻记录','$state')");
	// 			}else
	// 			{
	// 				$state=1;
	// 				$accounts=$_SESSION['accounts'];
	// 				M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,state)values('$accounts','查询官方给玩家冲钻记录','$state')");
	// 			}
	// 		}
			
	// 		if($_GET['rmb']!="")
	// 		{
	// 			if($_GET['rmb']==1)
	// 			{   
	// 				$post_select = "40元";
	// 				$loadgame=M('yp_apply_order')->where('order_gems=100 and order_status=2')->select();

	// 			}
	// 			if($_GET['rmb']==2)
	// 			{   
	// 				$post_select = "110元";
	// 				$loadgame=M('yp_apply_order')->where('order_gems=300 and order_status=2')->select();
	// 			}
	// 			if($_GET['rmb']==3)
	// 			{   
	// 				$post_select = "350元";
	// 				$loadgame=M('yp_apply_order')->where('order_gems=1000 and order_status=2')->select();
	// 			}				
	// 			if($_GET['rmb']==4)
	// 			{   
	// 				$post_select = "1000元";
	// 				$loadgame=M('yp_apply_order')->where('order_gems=3000 and order_status=2')->select();
	// 			}				
	// 			if($_GET['rmb']==5)
	// 			{   
	// 				$post_select = "3000元";
	// 				$loadgame=M('yp_apply_order')->where('order_gems=10000 and order_status=2')->select();
	// 			}				
	// 		}
	// 	}
	// 	$this->assign('page',$show);
	// 	$this->assign('post_select',$post_select);
	// 	$this->assign('loadgame',$loadgame);
	// 	$this->display();
	// }
	/*  当天活跃玩家       */
	public function active_player()
	{
	    login('您好，请先登录');
		$date1       = date("Y-m-d 23:55:55",strtotime("-1 day"));
		$date2       = date("Y-m-d 23:55:55",strtotime("-2 day"));
		$arr1['record_time']=array('between',array($date2,$date1));
		$deputy=M("","t_user_everyday_record","DB_CONFIG1")->select();
		//分页
		$count      = M("","t_user_everyday_record","DB_CONFIG1")->where($arr1)->count();
		$Page       = new \Org\Bjy\Page($count,25);
		$show       = $Page->show();

       
			
		$deputy = M("","t_user_everyday_record","DB_CONFIG1")->where($arr1)->order('record_time desc')->limit($Page->firstRow.','.$Page->listRows)->select();

		
		$this->assign('page',$show);
		
		if(IS_GET)
		{
			if($_GET['userid']!="" || $_GET['name']!="" AND $_GET['sdate']=="" AND $_GET['edate']=="" )
			{
				$w['userid']=array('like','%'.$_GET['userid'].'%');//把数据写到空数组去  
				$w['name']=array('like','%'.$_GET['name'].'%');//把数据写到空数组去  
				$deputy=M("","t_user_everyday_record","DB_CONFIG1")->where($w)->where($arr1)->select();
				if($deputy)
				{
					$state=0;
					$accounts=$_SESSION['accounts'];
					M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,state)values('$accounts','查询官方给玩家冲钻记录','$state')");
				}else
				{
					$state=1;
					$accounts=$_SESSION['accounts'];
					M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,state)values('$accounts','查询官方给玩家冲钻记录','$state')");
				}
			}	
			if($_GET['userid']=="" AND $_GET['name']=="" AND $_GET['sdate']!="" || $_GET['edate']!="")
			{
				$sdate=$_GET['sdate']; //get来的时间转为时间戳
				$edate=$_GET['edate'];	//get来的时间转为时间戳
				$arr['record_time']=array('between',array($sdate,$edate));
				$deputy=M("","t_user_everyday_record","DB_CONFIG1")->where($arr)->select();//时间不符合    需要修正！！！！
				if($deputy)
				{
					$state=0;
					$accounts=$_SESSION['accounts'];
					M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,state)values('$accounts','查询官方给玩家冲钻记录','$state')");
				}else
				{
					$state=1;
					$accounts=$_SESSION['accounts'];
					M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,state)values('$accounts','查询官方给玩家冲钻记录','$state')");
				}
			}
		}
		$sum=M("","t_user_everyday_record","DB_CONFIG1")->where($arr1)->count('userid');     //玩家总数、
		$this->assign('deputy',$deputy);
		$this->assign('sum',$sum);
		$this->display();
	}	
	//当天代理信息
	public function active_agent()
	{
		login('您好，请先登录');
		$date1       = date("Y-m-d 23:55:55",strtotime("-1 day"));
		$date2       = date("Y-m-d 23:55:55",strtotime("-2 day"));
		$arr1['record_time']=array('between',array($date2,$date1));
		$count      = M("","t_agent_total_record","DB_CONFIG1")->where($arr1)->count();
		$Page       = new \Org\Bjy\Page($count,25);
		$show       = $Page->show();
		
			
		$deputy = M("","t_agent_total_record","DB_CONFIG1")->where($arr1)->order('record_time desc')->limit($Page->firstRow.','.$Page->listRows)->select();  //echo M("","t_agent_total_record","DB_CONFIG1")->_sql();die;
			//dump($deputy);die;
		$this->assign('page',$show);
				
		if(IS_GET)
		{
			if($_GET['accounts']!="" || $_GET['name']!="" AND $_GET['sdate']=="" AND $_GET['edate']=="" )
			{
				$w['accounts']=array('like','%'.$_GET['accounts'].'%');//把数据写到空数组去  
				$w['name']=array('like','%'.$_GET['name'].'%');//把数据写到空数组去  
				$deputy=M("","t_agent_total_record","DB_CONFIG1")->where($w)->where($arr1)->select();
				if($deputy)
				{
					$state=0;
					$accounts=$_SESSION['accounts'];
					M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,state)values('$accounts','查询官方给玩家冲钻记录','$state')");
				}else
				{
					$state=1;
					$accounts=$_SESSION['accounts'];
					M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,state)values('$accounts','查询官方给玩家冲钻记录','$state')");
				}
			}	
			if($_GET['accounts']=="" AND $_GET['name']=="" AND $_GET['sdate']!="" || $_GET['edate']!="")
			{
				$sdate=$_GET['sdate']; //get来的时间转为时间戳
				$edate=$_GET['edate'];	//get来的时间转为时间戳
				$arr['record_time']=array('between',array($sdate,$edate));
				$deputy=M("","t_agent_total_record","DB_CONFIG1")->where($arr)->select();//时间不符合    需要修正！！！！
				if($deputy)
				{
					$state=0;
					$accounts=$_SESSION['accounts'];
					M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,state)values('$accounts','查询官方给玩家冲钻记录','$state')");
				}else
				{
					$state=1;
					$accounts=$_SESSION['accounts'];
					M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,state)values('$accounts','查询官方给玩家冲钻记录','$state')");
				}
			}
		}
		$sum=M("","t_agent_total_record","DB_CONFIG1")->where($arr1)->count('accounts');     //代理总数、
		$this->assign('deputy',$deputy);
		$this->assign('sum',$sum);
		$this->display();
	}
	//当天的总信息
	public function day_information()
	{
				login('您好，请先登录');
				
		$deputy=M("","t_everyday_total_record","DB_CONFIG1")->select();//表中的全部信息   选取最新的记录
		$cur_date= (date('Y-m-d H:i:s'));  //现在的时间

		$cur_date1= (date('Y-m-d 0:0:5'));//昨天时间

		$arr_time['create_time']=array('between',array($cur_date1,$cur_date));//进入数组  后查询

		$arr_agent_time['regtime']=array('between',array($cur_date1,$cur_date));//进入数组后查询代理表的数组
		$sum_users_cur=M("","t_users","DB_CONFIG1")->where($arr_time)->count('userid');//查询昨天到当天新增玩家
		$sum_agenr_cur=M("t_agent")->where($arr_agent_time)->count('accounts'); //查询昨天到当天新增代理
		$wx['account']=array('like','WX%');		

		$sum=M("","t_users","DB_CONFIG1")->where('online=1')->where($wx)->count('userid');//当前在线

		$sum_all_users=M("","t_users","DB_CONFIG1")->where($wx)->count('userid');//所有总数

		$sum_all_agent=M("t_agent")->count('accounts');
		
		$this->assign('deputy',$deputy);      //当天新增代理量 不对
		$this->assign('sum_all',$sum_all);
		$this->assign('sum_users_cur',$sum_users_cur);
		$this->assign('sum_agenr_cur',$sum_agenr_cur);
		$this->assign('sum_all_users',$sum_all_users);
		$this->assign('sum_all_agent',$sum_all_agent);
		$this->assign('sum',$sum);
		$this->display();
	}
				/* 代理商用户信息 */
	public function supervise()
	{
				login('您好，请先登录');
		$t_agent= M('','t_agent','DB_CONFIG0');
		$w=array();
		$count      = $t_agent->where($w)->where('referrer!=100')->count();
		$Page       = new \Org\Bjy\Page($count,20);
		$show       = $Page->show();
		$loadgame=$t_agent->where('referrer!=100')->order('regtime desc')->limit($Page->firstRow.','.$Page->listRows)->select();

		//接受get数据
		$userid=$_GET['userid'];
		$name=$_GET['name'];
		$userid=$_GET['userid'];
		if(IS_GET)
		{
			if($_GET['userid']!="" || $_GET['name']!="" AND $_GET['sdate']=="" AND $_GET['edate']=="" )
			{
				$w['accounts']=array('like','%'.$userid.'%');													//把数据写到空数组去  
				$w['username']=array('like','%'.$name.'%');	//把数据写到空数组		

				$count      = $t_agent->where($w)->where('referrer!=100')->count();
				$Page       = new \Org\Bjy\Page($count,20);
				$show       = $Page->show();
				$loadgame=$t_agent->where($w,'referrer!=100')->limit($Page->firstRow.','.$Page->listRows)->select();
				if($loadgame)
				{
					$state=0;
					$accounts=$_SESSION['accounts'];
					M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,state)values('$accounts','查询代理信息','$state')");
				}else
				{
					$state=1;
					$accounts=$_SESSION['accounts'];
					M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,state)values('$accounts','查询代理信息','$state')");
				}
			}	
			if($_GET['userid']=="" AND $_GET['name']=="" AND $_GET['sdate']!="" || $_GET['edate']!="")
			{
				$sdate=$_GET['sdate']; 																//get来的时间转为时间戳
				$edate=$_GET['edate'];																//get来的时间转为时间戳
				$arr['regtime']=array('between',array($sdate,$edate));

				$count      = $t_agent->where($arr)->where('referrer!=100')->count();
				$Page       = new \Org\Bjy\Page($count,20);
				$show       = $Page->show();
				$loadgame=M('t_agent')->where($arr)->where('referrer!=100')->limit($Page->firstRow.','.$Page->listRows)->select();//时间不符合    需要修正！！！！
				if($loadgame)
				{
					$state=0;
					$accounts=$_SESSION['accounts'];
					M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,state)values('$accounts','查询代理商信息','$state')");
				}else
				{
					$state=1;
					$accounts=$_SESSION['accounts'];
					M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,state)values('$accounts','查询代理商信息','$state')");
				}				
			}
		}
		$sum=M('t_agent')->where('agencylv!=100')->count('accounts');
		$this->assign('page',$show);
		$this->assign('loadgame',$loadgame);
		$this->assign('sum',$sum);
		$this->display();
	}

	/*-------------更改代理信息--------------*/
	public function change()
	{				
		login('您好，请先登录');
		$accounts=I('get.accounts');
		$rebates=M('t_agent')->where('accounts='.$accounts)->find();
		$authority = M('t_agent')->where('agencylv=100')->find();//总权限
		//dump($authority['accounts']);die;
		
		if(IS_POST)
		{    
			$agencylv=$_POST['agencylv'];
			$names=$_POST['names'];
			$referrer=$_POST['referrer'];
			if($agencylv==0 && $referrer!=$authority['accounts']){
				error('代理等级修改为总代理时，上级必须为总公司');
			}
			if($names==""){
				error('姓名不可为空');
			}
			if($referrer==""){
				error('上级代理不可为空');
			}
			$shangji=M('t_agent')->where('accounts='.$referrer)->find();
			if($shangji!=""){
				if(M("","","DB_CONFIG0")->execute("update t_agent set agencylv='$agencylv',username='$names',referrer='$referrer' where accounts=".$accounts))
				{
					change('更改成功');
				}else{
					change('未做更改');
				}
		    }else{
		    	error('上级代理输入有误，不存在该代理');
		    }
		}
		
		$this->assign('rebates',$rebates);
		$this->display();
	}

	/*-------------删除代理--------------*/
	public function delagent()
	{				
		
		$accounts=I('get.accounts');
		$access=M('t_agent_access_config')->where('accounts_id='.$_SESSION['accounts'])->find();
		$t_agent = M('t_agent');
		//dump($access['paral']);die;
		if($access['paral'] ==1){
			$state=$t_agent->delete($accounts);
			//dump($state);die;
			if ($state){
				change('删除成功');
			}else{
				change('删除失败');
			}
		}else{
			change('您没有权限删除该代理');
		}
		
	}
	
	/*    代理转账记录    */
	public function recordpay()
	{
				login('您好，请先登录');
			$w=array('manner=2');
			$count      = M('t_agent_add_cards_to_agent')->where($w)->count();
			$Page       = new \Org\Bjy\Page($count,20);
			$show       = $Page->show();
			$presnted = M('t_agent_add_cards_to_agent')->where($w)->order('regtime desc')->limit($Page->firstRow.','.$Page->listRows)->select();
			
			if(IS_GET)
			{
				if($_GET['userid']!="" || $_GET['name']!="" AND $_GET['sdate']=="" AND $_GET['edate']=="" )
				{
					$w['benefactor']=array('like','%'.$_GET['userid'].'%');												//把数据写到空数组去  
					$w['recipient']=array('like','%'.$_GET['name'].'%');													//把数据写到空数组	
					$count      = M('t_agent_add_cards_to_agent')->where($w)->where('manner=2')->count();
					$Page       = new \Org\Bjy\Page($count,20);
					$show       = $Page->show();	
					$presnted=M('t_agent_add_cards_to_agent')->where($w)->where('manner=2')->limit($Page->firstRow.','.$Page->listRows)->select();			
					if($presnted)
					{
						$state=0;
						$accounts=$_SESSION['accounts'];
						M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,state)values('$accounts','查询代理充值记录','$state')");
					}else
					{
						$state=1;
						$accounts=$_SESSION['accounts'];
						M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,state)values('$accounts','查询代理充值记录','$state')");
					}
				}	
				if($_GET['userid']=="" AND $_GET['name']=="" AND $_GET['sdate']!="" || $_GET['edate']!="")
				{
					$sdate=$_GET['sdate'];																		//get来的时间转为时间戳
					$edate=$_GET['edate'];																		//get来的时间转为时间戳
					$arr['regtime']=array('between',array($sdate,$edate));
					$count      = M('t_agent_add_cards_to_agent')->where($arr)->where('manner=2')->count();
					$Page       = new \Org\Bjy\Page($count,20);
					$show       = $Page->show();	
					$presnted=M('t_agent_add_cards_to_agent')->where($arr)->where('manner=2')->limit($Page->firstRow.','.$Page->listRows)->select();  //时间不符合    需要修正！！！！
					if($presnted)
					{
						$state=0;
						$accounts=$_SESSION['accounts'];
						M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,state)values('$accounts','查询代理充值记录','$state')");
					}else
					{
						$state=1;
						$accounts=$_SESSION['accounts'];
						M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,state)values('$accounts','查询代理充值记录','$state')");
					}
				}
			}
		$this->assign('page',$show);
		$this->assign('presnted',$presnted);
		$this->display();
	}
	/* 代理用户返利页面 */
	public function deduct()
	{		
				login('您好，请先登录');
		
		$deduct=M("t_agent")->query("SELECT t_agent.*,t_rebate_quota.* FROM t_agent  LEFT JOIN t_rebate_quota ON t_agent.accounts=t_rebate_quota.id  WHERE   t_rebate_quota.top_limit >= t_agent.rechargetotal AND t_rebate_quota.botton_limit <= t_agent.rechargetotal");
		//dump($deduct);die;
		if(IS_GET)
		{
			if($_GET['userid']!="")
			{
				

				$deduct=M("t_agent")->query("SELECT t_agent.*,t_rebate_quota.* FROM t_agent  LEFT JOIN t_rebate_quota ON t_agent.accounts=t_rebate_quota.id  WHERE   t_rebate_quota.top_limit >= t_agent.rechargetotal AND t_rebate_quota.botton_limit <= t_agent.rechargetotal AND t_agent.accounts like '%".I('get.userid')."%'");
				if($deduct)
				{
					$state=0;
					$accounts=$_SESSION['accounts'];
					M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,state)values('$accounts','查询代理充值记录','$state')");
				}else
				{
					$state=1;
					$accounts=$_SESSION['accounts'];
					M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,state)values('$accounts','查询代理充值记录','$state')");
				}
			}	
			if($_GET['sdate']!="" || $_GET['edate']!="")
			{
				$sdate=$_GET['sdate'];																		//get来的时间转为时间戳
				$edate=$_GET['edate'];																		//get来的时间转为时间戳
				
				$deduct=M("t_agent")->query("SELECT t_agent.*,t_rebate_quota.* FROM t_agent  LEFT JOIN t_rebate_quota ON t_agent.accounts=t_rebate_quota.id  WHERE   t_rebate_quota.top_limit >= t_agent.rechargetotal AND t_rebate_quota.botton_limit <= t_agent.rechargetotal AND t_agent.regtime between '$sdate' AND '$edate'");
				if($deduct)
				{
					$state=0;
					$accounts=$_SESSION['accounts'];
					M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,state)values('$accounts','查询代理充值记录','$state')");
				}else
				{
					$state=1;
					$accounts=$_SESSION['accounts'];
					M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,state)values('$accounts','查询代理充值记录','$state')");
				}
			}
		}
		$this->assign('deduct',$deduct);
		$this->display();
	}
	/*-------------更改返利额度--------------*/
	public function rebates()
	{				
		login('您好，请先登录');
		

		$accounts=I('get.accounts');
		$rechargetotal=I('get.rechargetotal');
		$deduct=M('t_agent')->where('accounts='.$accounts)->find();
		//$sql=M("t_rebate_quota")->where('id='.$accounts)->where('top_limit >='.$rechargetotal.' AND botton_limit <='.$rechargetotal)->find();
        //dump($sql);die;
		//dump($deduct['agencylv']);die;
		if(IS_POST)
		{    
			$first=$_POST['first'];
			$second=$_POST['second'];
			$disbate=$_POST['disbate'];
			//dump($disbate);die;
            
            M("","","DB_CONFIG0")->execute("update t_rebate_quota set first_upper_rebate='$first',second_upper_rebate='$second' where id=".$accounts." AND top_limit >=".$rechargetotal." AND botton_limit <=".$rechargetotal );
            M("","","DB_CONFIG0")->execute("update t_rebate_quota set disbate='$disbate' where id=".$accounts);
            deduct('更改成功');
		}
		$this->assign('deduct',$deduct);
		$this->assign('accounts',$accounts);
		$this->assign('rechargetotal',$rechargetotal);
		$this->display();
	}
   //---------------------------配牌--------------------------
	public function guration()
	{				
		$userid=I('get.userid');
		$isconfigpai=I('get.isconfigpai');
		
		if($sql = M('','','DB_CONFIG1')->execute("update t_users set isconfigpai='$isconfigpai' where userid=".$userid)){
			gura('更改成功');
		}else{
			gura('未做更改');
		}
		
	}
	//---------------------------权限配置--------------------------
	public function purview()
	{				
		login('您好，请先登录');
		$sql = M("t_authority_configuration")->where("grade=0")->find();
		 //dump($sql);die;
		if(IS_POST)
		{    
			$searchplayer=$_POST['searchplayer'];
			if ($searchplayer=="") {
				$searchplayer = 0;
			}
			$zengs=$_POST['zengs'];
			if ($zengs=="") {
				$zengs = 0;
			}
			$creatuser=$_POST['creatuser'];
			if ($creatuser=="") {
				$creatuser = 0;
			}
			$leixing=$_POST['leixing'];
			if ($leixing=="") {
				$leixing = 0;
			}
			$shangji=$_POST['shangji'];
			if ($shangji=="") {
				$shangji = 0;
			}
			$myadmin=$_POST['myadmin'];
			if ($myadmin=="") {
				$myadmin = 0;
			}
			$myinfoxia=$_POST['myinfoxia'];
			if ($myinfoxia=="") {
				$myinfoxia = 0;
			}
			$drilling=$_POST['drilling'];
			if ($drilling=="") {
				$drilling = 0;
			}
			$agentmodi=$_POST['agentmodi'];
			if ($agentmodi=="") {
				$agentmodi = 0;
			}
			$agentcharge=$_POST['agentcharge'];
			if ($agentcharge=="") {
				$agentcharge = 0;
			}
			$buygold=$_POST['buygold'];
			if ($buygold=="") {
				$buygold = 0;
			}
			$subordinate=$_POST['subordinate'];
			if ($subordinate=="") {
				$subordinate = 0;
			}
			$policy=$_POST['policy'];
			if ($policy=="") {
				$policy = 0;
			}
			$myinfo=$_POST['myinfo'];
			if ($myinfo=="") {
				$myinfo = 0;
			}
			$setnotice=$_POST['setnotice'];
			if ($setnotice=="") {
				$setnotice = 0;
			}
			$policyedit=$_POST['policyedit'];
			if ($policyedit=="") {
				$policyedit = 0;
			}
			$payoff=$_POST['payoff'];
			if ($payoff=="") {
				$payoff = 0;
			}
			$playercharge=$_POST['playercharge'];
			if ($playercharge=="") {
				$playercharge = 0;
			}
			//dump($searchplayer);die;
			if(M('','','DB_CONFIG')->execute("update t_authority_configuration set searchplayer='$searchplayer',zengs='$zengs',creatuser='$creatuser',leixing='$leixing',zengs='$zengs',shangji='$shangji',myadmin='$myadmin',myinfoxia='$myinfoxia',drilling='$drilling',agentmodi='$agentmodi',agentcharge='$agentcharge',buygold='$buygold',subordinate='$subordinate',policy='$policy',myinfo='$myinfo',setnotice='$setnotice' ,policyedit='$policyedit',payoff='$payoff',playercharge='$playercharge' where grade=0")){
				error('更改成功');
			}else{
				error('未做更改');
			}
		}
		$this->assign('sql',$sql);
		$this->display();
	}
	//---------------------------权限配置--------------------------
	public function purview01()
	{				
		login('您好，请先登录');
		$sql = M("t_authority_configuration")->where("grade=1")->find();
		 //dump($sql);die;
		if(IS_POST)
		{    
			$searchplayer=$_POST['searchplayer'];
			if ($searchplayer=="") {
				$searchplayer = 0;
			}
			$zengs=$_POST['zengs'];
			if ($zengs=="") {
				$zengs = 0;
			}
			$creatuser=$_POST['creatuser'];
			if ($creatuser=="") {
				$creatuser = 0;
			}
			$leixing=$_POST['leixing'];
			if ($leixing=="") {
				$leixing = 0;
			}
			$shangji=$_POST['shangji'];
			if ($shangji=="") {
				$shangji = 0;
			}
			$myadmin=$_POST['myadmin'];
			if ($myadmin=="") {
				$myadmin = 0;
			}
			$myinfoxia=$_POST['myinfoxia'];
			if ($myinfoxia=="") {
				$myinfoxia = 0;
			}
			$drilling=$_POST['drilling'];
			if ($drilling=="") {
				$drilling = 0;
			}
			$agentmodi=$_POST['agentmodi'];
			if ($agentmodi=="") {
				$agentmodi = 0;
			}
			$agentcharge=$_POST['agentcharge'];
			if ($agentcharge=="") {
				$agentcharge = 0;
			}
			$buygold=$_POST['buygold'];
			if ($buygold=="") {
				$buygold = 0;
			}
			$subordinate=$_POST['subordinate'];
			if ($subordinate=="") {
				$subordinate = 0;
			}
			$policy=$_POST['policy'];
			if ($policy=="") {
				$policy = 0;
			}
			$myinfo=$_POST['myinfo'];
			if ($myinfo=="") {
				$myinfo = 0;
			}
			$setnotice=$_POST['setnotice'];
			if ($setnotice=="") {
				$setnotice = 0;
			}
			$policyedit=$_POST['policyedit'];
			if ($policyedit=="") {
				$policyedit = 0;
			}
			$payoff=$_POST['payoff'];
			if ($payoff=="") {
				$payoff = 0;
			}
			$playercharge=$_POST['playercharge'];
			if ($playercharge=="") {
				$playercharge = 0;
			}
			//dump($searchplayer);die;
			if(M('','','DB_CONFIG')->execute("update t_authority_configuration set searchplayer='$searchplayer',zengs='$zengs',creatuser='$creatuser',leixing='$leixing',zengs='$zengs',shangji='$shangji',myadmin='$myadmin',myinfoxia='$myinfoxia',drilling='$drilling',agentmodi='$agentmodi',agentcharge='$agentcharge',buygold='$buygold',subordinate='$subordinate',policy='$policy',myinfo='$myinfo',setnotice='$setnotice' ,policyedit='$policyedit',payoff='$payoff',playercharge='$playercharge' where grade=1")){
				error('更改成功');
			}else{
				error('未做更改');
			}
		}
		$this->assign('sql',$sql);
		$this->display();
	}
	//---------------------------权限配置--------------------------
	public function purview02()
	{				
		login('您好，请先登录');
		$sql = M("t_authority_configuration")->where("grade=2")->find();
		 //dump($sql);die;
		if(IS_POST)
		{    
			$searchplayer=$_POST['searchplayer'];
			if ($searchplayer=="") {
				$searchplayer = 0;
			}
			$zengs=$_POST['zengs'];
			if ($zengs=="") {
				$zengs = 0;
			}
			$creatuser=$_POST['creatuser'];
			if ($creatuser=="") {
				$creatuser = 0;
			}
			$leixing=$_POST['leixing'];
			if ($leixing=="") {
				$leixing = 0;
			}
			$shangji=$_POST['shangji'];
			if ($shangji=="") {
				$shangji = 0;
			}
			$myadmin=$_POST['myadmin'];
			if ($myadmin=="") {
				$myadmin = 0;
			}
			$myinfoxia=$_POST['myinfoxia'];
			if ($myinfoxia=="") {
				$myinfoxia = 0;
			}
			$drilling=$_POST['drilling'];
			if ($drilling=="") {
				$drilling = 0;
			}
			$agentmodi=$_POST['agentmodi'];
			if ($agentmodi=="") {
				$agentmodi = 0;
			}
			$agentcharge=$_POST['agentcharge'];
			if ($agentcharge=="") {
				$agentcharge = 0;
			}
			$buygold=$_POST['buygold'];
			if ($buygold=="") {
				$buygold = 0;
			}
			$subordinate=$_POST['subordinate'];
			if ($subordinate=="") {
				$subordinate = 0;
			}
			$policy=$_POST['policy'];
			if ($policy=="") {
				$policy = 0;
			}
			$myinfo=$_POST['myinfo'];
			if ($myinfo=="") {
				$myinfo = 0;
			}
			$setnotice=$_POST['setnotice'];
			if ($setnotice=="") {
				$setnotice = 0;
			}
			$policyedit=$_POST['policyedit'];
			if ($policyedit=="") {
				$policyedit = 0;
			}
			$payoff=$_POST['payoff'];
			if ($payoff=="") {
				$payoff = 0;
			}
			$playercharge=$_POST['playercharge'];
			if ($playercharge=="") {
				$playercharge = 0;
			}
			//dump($searchplayer);die;
			if(M('','','DB_CONFIG')->execute("update t_authority_configuration set searchplayer='$searchplayer',zengs='$zengs',creatuser='$creatuser',leixing='$leixing',zengs='$zengs',shangji='$shangji',myadmin='$myadmin',myinfoxia='$myinfoxia',drilling='$drilling',agentmodi='$agentmodi',agentcharge='$agentcharge',buygold='$buygold',subordinate='$subordinate',policy='$policy',myinfo='$myinfo',setnotice='$setnotice' ,policyedit='$policyedit',payoff='$payoff',playercharge='$playercharge' where grade=2")){
				error('更改成功');
			}else{
				error('未做更改');
			}
		}
		$this->assign('sql',$sql);
		$this->display();
	}
	//---------------------------登录用户操作日志--------------------------
	public function journal()
	{				
				login('您好，请先登录');
		$count      = M('t_journal')->count();
		$Page       = new \Org\Bjy\Page($count,15);
		$show       = $Page->show();
		$a = $Page->firstRow;
		$b = $Page->listRows;

		$sql=M("","","DB_CONFIG0")->query("select * from t_journal order by times desc limit $a, $b"); 
		if(IS_GET)
		{
			if($_GET['userid']!="" || $_GET['name']!="" AND $_GET['sdate']=="" AND $_GET['edate']=="" )
			{
				$w['action']=array('like','%'.$_GET['name'].'%');												//把数据写到空数组去  
				$w['accounts']=array('like','%'.$_GET['userid'].'%');												//把数据写到空数组去  
				$sql=M('t_journal')->where($w)->select();														//echo M('t_agent_add_cards_to_agent')->_sql();die;
				if($sql)
				{
					$state=0;
					$accounts=$_SESSION['accounts'];
					M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,state)values('$accounts','查询代理操作记录','$state')");
				}else
				{
					$state=1;
					$accounts=$_SESSION['accounts'];
					M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,state)values('$accounts','查询代理操作记录','$state')");
				}
			}	
			if($_GET['userid']=="" AND $_GET['name']=="" AND $_GET['sdate']!="" || $_GET['edate']!="")
			{
				$sdate=$_GET['sdate'];																		//get来的时间转为时间戳
				$edate=$_GET['edate'];																		//get来的时间转为时间戳
				$arr['times']=array('between',array($sdate,$edate));															//判断大于等于起始时间的条件
				$sql=M('t_journal')->where($arr)->select();  //时间不符合    需要修正！！！！				
				if($sql)
				{
					$state=0;
					$accounts=$_SESSION['accounts'];
					M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,state)values('$accounts','查询代理操作记录','$state')");
				}else
				{
					$state=1;
					$accounts=$_SESSION['accounts'];
					M('','','DB_CONFIG0')->execute("insert into t_journal(accounts,action,state)values('$accounts','查询代理操作记录','$state')");
				}				
			}
		}
		$this->assign('sql',$sql);
		$this->assign('page',$show);
		$this->display();
	}

	
}





































































